/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
 
package test;

import java.util.*;
import java.lang.*;
import bgtp.*;

public class ServerTest
{

    public static void main(String[] args)
    {
	MQInterface	all	       = new MessageQueue();
	BGTPmm		mm	       = BGTPmm.getInstance();
	Registrator	wrkRegistrator = new Registrator(mm);
	Acceptor	netAcceptor    = new Acceptor("localhost", "10100", wrkRegistrator);

	mm.subscribe(new Filter("Action ~ '.*'"), all);
	wrkRegistrator.start();
	netAcceptor.start();
	mm.start();

	while(true)
	    {
		if(all.size() > 0)
		    {
			TreeMap<String, String> tmp = all.get();
			for(String item : tmp.keySet())
			    {
				System.out.printf("%s: %s\n", item, tmp.get(item));
			    }
			System.out.println("");
			
			tmp.put("ReqType", "POST / HTTP/1.1");
			mm.send(tmp);
		    }
		else
		    {
			Helper.sleep(200);
		    }
		//System.out.println("==========ServerTest==========");
	    }
    }
}